<!DOCTYPE html>
<html>

<head>
    <title>个人页面</title>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap-4.1.1-dist/css/bootstrap.min.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap-4.1.1-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css">
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/userProfiles.css"/>
    <script src="/js/plugins/jrender/jrender.min.js"></script>
    <link rel="stylesheet" href="/js/plugins/dialog2/dialog.css">
    <script src="/js/plugins/dialog2/dialog.min.js"></script>
    <script src="/js/common.js"></script>
    <!--序列化表单-->
    <script src="/js/plugins/form/jquery.form.js"></script>
    <script>
        $(function () {
            var user = JSON.parse(sessionStorage.getItem("user"));
            //获取当前页面的id
            var paramId = getParams().id;
            //查询当前登录用户的数据
            $.get("/users/id", {id: paramId}, function (data) {
                $("#headImgUrl").attr("src", data.headImgUrl);
                $(".name").html(data.nickName);
                $("#sign").html(data.sign);

            })

            var state = 1;
            //判断当前用户是否已关注
            if (user) {
                $.get("/users/selectStateByUserId", {userId: user.id, hearImgUrlId: paramId}, function (data) {
                    if (data.state == state) {
                        $("#followBtn").html("取消关注");
                    } else {
                        $("#followBtn").html("关注");
                        state = 0;
                    }

                })
            }
            //查询关注和粉丝数
            $.get("/users/selectAandF", {id: paramId}, function (data) {
                $("#attention").html(data.attentionId);
                $("#fancier").html(data.fancierId);
            })
            //点击关注/取消关注
            $("#followBtn").click(function () {

                if (user) {
                    //自己不能关注自己
                    if (paramId == user.id) {
                        $(document).dialog({
                            type: 'notice',
                            infoText: '你无时无刻不在关注自己',
                            autoClose: 2500,
                            position: 'center'  // center: 居中; bottom: 底部
                        });
                    } else if (state == 0) {
                        $.post("/users/save", {userId: user.id, hearImgUrlId: paramId}, function (data) {
                            window.location.reload();
                        })
                    } else {

                        $.ajax({
                            url: "/users/update",
                            type: "PUT",
                            data: {userId: user.id, hearImgUrlId: paramId},
                            dataType: "json",
                            success: function () {
                                window.location.reload();
                            }
                        })
                        /*
                                                $.put("/users/update", {userId: user.id, hearImgUrlId: paramId}, function (data) {
                                                    console.log(data);
                                                    window.location.reload();
                                                })*/
                    }
                } else {
                    window.location.href = "/login.html";
                }
            });

            var currentPage = 1;//当前页
            var pages = 1;//总页数
            var travelData = [];
            var wishList = [];
            var commentData = [];

            function query() {
                //获取我的游记列表,某个用户的所有列表
                $.get("/usersProfilers/travels/" + paramId, {currentPage: currentPage}, function (data) {
                    console.log(data);
                    $("#totalTravels").html(data.list.length);
                    $.merge(travelData, data.list);
                    var json = {
                        list: travelData
                    };
                    //回显数据
                    $("#travels").renderValues(json, {
                        getHref: getHref

                    });
                });

                //获取当前用户的旅行单
                $.get("/usersProfilers/StrategyWishList/" + paramId, {currentPage: currentPage}, function (data) {
                    console.log(data);
                    $("#StrategieswishList").html(data.list.length);
                    $.merge(wishList, data.list);
                    var json = {
                        list: wishList
                    };
                    //回显数据
                    $("#wishList").renderValues(json, {
                        getHref: getHref

                    });
                });

                //获取当前用户攻略的评论
                $.get('/usersProfilers/strategyComments/' + paramId, {currentPage: currentPage}, function (data) {
                    $("#totalStrategyComments").html(data.list.length);
                    $.merge(commentData, data.list);
                    var json = {
                        list: commentData
                    };
                    $("#comments").renderValues(json, {
                        getHref: function (item, value) {
                            var url = $(item).data("href");
                            $(item).attr("href", url + value);
                        },
                        getStar: function (item, value) {
                            var temp = "";
                            for (var i = 0; i < value; i++) {
                                temp += '<i class="fa fa-star"></i>';
                            }
                            for (var i = 0; i < 5 - value; i++) {
                                temp += '<i class="fa fa-star-o"></i>';
                            }
                            $(item).html(temp);
                        }
                    });
                });
            }

            query();
        })
    </script>
</head>
<body>
<div class="container bg" style="background-image: url(&quot;/img/user/bg.jpeg&quot;);">
    <a href="javascript:window.history.go(-1)" class="my-arrow">
        <span><i class="fa fa-chevron-left fa-2x"></i></span>
    </a>
    <div class="container">
        <div class="info">
            <img id="headImgUrl" class="rounded-circle" width="17%">
            <p class="name"></p>
            <p id="sign"></p>

            <div class="row num">
                <div class="col-2 border border-left-0 border-top-0 border-bottom-0">
                    <div>
                        <span id="attention"></span>
                    </div>
                    <div>
                        <span>关注</span>
                    </div>
                </div>
                <div class="col-2">
                    <div>
                        <span id="fancier"></span>
                    </div>
                    <div>
                        <span>粉丝</span>
                    </div>
                </div>
                <div class="col">
                    <button class="btn btn-outline-light ibtn" id="letterBtn">私信</button>
                    <button class="btn btn-success ibtn" id="followBtn">关注</button>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="tabs" id="demo">
    <ul class="nav nav-pills nav-justified  border border-left-0 border-top-0 border-right-0" id="pills-tab"
        role="tablist">
        <li class="nav-item">
            <a class="nav-link active" id="travels-tab" data-toggle="pill" href="#travels">
                TA的游记[<span id="totalTravels"></span>]
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link " id="comments-tab" data-toggle="pill" href="#comments">
                TA的点评[<span id="totalStrategyComments"></span>]
            </a>
        </li>
        <li class="nav-item">
            <a class="nav-link" id="pills-contact-tab" data-toggle="pill" href="#wishList">
                TA的旅行单[<span id="StrategieswishList"></span>]
            </a>
        </li>
    </ul>
    <div class="container tab-content" id="pills-tabContent">
        <div class="tab-pane fade show active" id="travels">
            <dl class="travels" render-loop="list">
                <dd>
                    <a data-href="travelContent.html?id=" render-fun="getHref" render-key="list.id">
                        <img render-src="list.coverUrl" style="width:100%;height: 100%;">
                        <p><span class="title" render-html="list.title"></span>
                        </p>
                    </a>
                    <hr>
                </dd>
            </dl>
        </div>
        <div class="comment tab-pane fade " id="comments">
            <div render-loop="list">
                <div class="row">
                    <div class="col-2 comment-head">
                        <img class="rounded-circle" render-src="list.user.headImgUrl">
                    </div>
                    <div class="col">
                        <span class="comment-star" render-fun="getStar" render-key="list.starNum"></span>

                        <span class="comment-date" render-html="list.createTime"></span>
                        <div class="comment-content">
                            <a render-key="list.id" render-fun="getHref" data-href="strategyComment.html?id=">
                                <p render-html="list.content"></p>
                            </a>
                        </div>
                        <ul class="comment-img" render-loop="list.imgArr">
                            <li>
                                <img render-src="list.imgArr.self">
                            </li>
                        </ul>

                        <div class="comment-link">
                            <a render-key="list.id" render-fun="getHref" data-href="strategyCatalogs.html?id=">
                                <img render-src="list.strategy.coverUrl"> <span
                                    render-html="list.strategy.title"></span>
                                <i class="fa fa-angle-right fa-2x"></i>
                            </a>
                        </div>

                    </div>
                </div>
            </div>

        </div>
        <div class="tab-pane fade" id="wishList">
            <dl class="list" render-loop="list">
                <dd>
                    <a data-href="strategyCatalogs.html?id=" render-fun="getHref" render-key="list.strategy.id">
                        <img render-src="list.strategy.coverUrl">
                        <p><span class="title" render-html="list.strategy.title"></span>
                        </p>
                    </a>
                    <hr>
                </dd>
            </dl>
        </div>
    </div>
</div>


</body>
</html>